<!DOCTYPE html>
<html>
<head th:include="common/header_css::header('霸王餐小程序后台管理-商品信息','%mfile%datepicker%summernote')"></head>
<!--<head th:include="common/header_css::header('霸王餐小程序后台管理-商户管理-banner配置')"></head>-->
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div th:replace="common/toolbar::toolbar('首页轮播管理')"></div>
        <div th:replace="common/search::search('%add')"></div>
    </div>
</div>

<!--添加Banner模态框-->
<div id="modal-add-form" class="modal fade" aria-hidden="true">
    <div class="modal-dialog" style="width: 800px;">
        <div class="modal-content">
            <div class="modal-body">
                <div class="row">
                    <h3 class="m-t-none m-b">幻灯片添加</h3>
                    <div class="col-sm-12">
                        <div class="ibox float-e-margins">
                            <div class="ibox-content">
                                <form id="aform" method="post" class="form-horizontal" action="add"
                                      onsubmit="return checkAdd()">
                                    <div class="row">
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label class="col-sm-4 control-label">名称</label>
                                                <div class="col-sm-8">
                                                    <input class="form-control" name="name"
                                                           type="text" maxlength="50"/>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label class="col-sm-4 control-label">类型</label>
                                                <div class="col-sm-8">
                                                    <select class="form-control" name="hyid">
                                                        <option value="">首页</option>
                                                        <option th:each="bus,userStat:${business}"
                                                                th:value="${bus.id}" th:text="${bus.name}"></option>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <!--<div class="row">-->
                                        <!--<div class="col-md-6">-->
                                            <!--<div class="form-group">-->
                                                <!--<label class="col-sm-4 control-label">开始时间-->
                                                <!--</label>-->
                                                <!--<div class="col-sm-8">-->
                                                    <!--<input type="date" class="form-control selectData" readonly-->
                                                           <!--id="startTime" name="startTime">-->
                                                <!--</div>-->
                                            <!--</div>-->
                                        <!--</div>-->
                                        <!--<div class="col-md-6">-->
                                            <!--<div class="form-group">-->
                                                <!--<label class="col-sm-4 control-label">结束时间-->
                                                <!--</label>-->
                                                <!--<div class="col-sm-8">-->
                                                    <!--<input type="date" class="form-control selectData" readonly-->
                                                           <!--id="endTime" name="endTime">-->
                                                <!--</div>-->
                                            <!--</div>-->
                                        <!--</div>-->
                                    <!--</div>-->

                                    <div class="row">
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label class="col-sm-4 control-label">链接类型*
                                                </label>
                                                <div class="col-sm-8">
                                                    <select class="form-control" name="linktype">
                                                        <option value="0">默认</option>
                                                        <option value="1">H5详情页</option>
                                                        <option value="2">商品分类页</option>
                                                        <option value="3">商品详情页</option>
                                                        <!--<option value="4">资讯详情页</option>-->
                                                        <!--<option value="5">店铺详情页</option>-->
                                                        <option value="9">功能页</option>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label class="col-sm-4 control-label">媒体类型*
                                                </label>
                                                <div class="col-sm-8">
                                                    <select class="form-control" name="type">
                                                        <option value="1">图片</option>
                                                        <option value="2">视频</option>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label class="col-sm-4 control-label">链接地址</label>
                                                <div class="col-sm-8">
                                                    <input class="form-control" name="link" type="text" maxlength="100"/>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label class="col-sm-4 control-label">排序*
                                                </label>
                                                <div class="col-sm-8">
                                                    <input class="form-control" name="sort" required type="number"/>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">描述</label>
                                                <div class="col-sm-10">
                                                            <textarea class="form-control" name="info" maxlength="500"></textarea>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">图片地址*
                                                </label>
                                                <div class="col-sm-10">
                                                    <input id="mfile2" name="mfile" type="file" class="file"/>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-4 col-sm-offset-2">
                                            <button class="btn btn-primary" type="submit">保存内容</button>
                                            <button data-toggle="modal" type="button" class="btn btn-white"href="#modal-add-form">取消</button>
                                        </div>
                                    </div>
                                    <input id="hidpic2" name="pic" type="hidden" value="" required="required"/>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!--修改Banner模态框-->
<div id="modal-form" class="modal fade" aria-hidden="true">
    <div class="modal-dialog" style="width: 800px;">
        <div class="modal-content">
            <div class="modal-body">
                <div class="row">
                    <h3 class="m-t-none m-b">幻灯片修改</h3>
                    <div class="col-sm-12">
                        <div class="ibox float-e-margins">
                            <div class="ibox-content">
                                <form id="mform" method="post" class="form-horizontal" action="modify"
                                      onsubmit="return checkModify()">
                                    <div class="row">
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label class="col-sm-4 control-label">名称</label>
                                                <div class="col-sm-8">
                                                    <input class="form-control" id="name" name="name"
                                                           type="text" maxlength="50"/>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label class="col-sm-4 control-label">类型</label>
                                                <div class="col-sm-8">
                                                    <select class="form-control" name="hyid" id="hyid">
                                                        <option value="">首页</option>
                                                        <option th:each="bus,userStat:${business}"
                                                                th:value="${bus.id}" th:text="${bus.name}"></option>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <!--<div class="row">-->
                                        <!--<div class="col-md-6">-->
                                            <!--<div class="form-group">-->
                                                <!--<label class="col-sm-4 control-label">开始时间</label>-->
                                                <!--<div class="col-sm-8">-->
                                                    <!--<input type="text" class="form-control selectData" readonly-->
                                                           <!--id="startTime2" name="startTime">-->
                                                <!--</div>-->
                                            <!--</div>-->
                                        <!--</div>-->
                                        <!--<div class="col-md-6">-->
                                            <!--<div class="form-group">-->
                                                <!--<label class="col-sm-4 control-label">结束时间</label>-->
                                                <!--<div class="col-sm-8">-->
                                                    <!--<input type="text" class="form-control selectData" readonly-->
                                                           <!--id="endTime2" name="endTime">-->
                                                <!--</div>-->
                                            <!--</div>-->
                                        <!--</div>-->
                                    <!--</div>-->
                                    <div class="row">
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label class="col-sm-4 control-label">链接类型*
                                                </label>
                                                <div class="col-sm-8">
                                                    <select class="form-control" name="linktype" id="linktype">
                                                        <option value="0">默认</option>
                                                        <option value="1">H5详情页</option>
                                                        <option value="2">商品分类页</option>
                                                        <option value="3">商品详情页</option>
                                                        <!--<option value="4">资讯详情页</option>-->
                                                        <!--<option value="5">店铺详情页</option>-->
                                                        <option value="9">功能页</option>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label class="col-sm-4 control-label">媒体类型*
                                                </label>
                                                <div class="col-sm-8">
                                                    <select class="form-control" name="type" id="type">
                                                        <option value="1">图片</option>
                                                        <option value="2">视频</option>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label class="col-sm-4 control-label">链接地址</label>
                                                <div class="col-sm-8">
                                                    <input class="form-control" id="link" name="link"
                                                           type="text" maxlength="100"/>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label class="col-sm-4 control-label">排序*
                                                </label>
                                                <div class="col-sm-8">
                                                    <input class="form-control" id="sort" name="sort" required type="number"/>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">描述</label>
                                                <div class="col-sm-10">
                                                    <textarea id="info" name="info" class="form-control" maxlength="500"></textarea>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">图片地址</label>
                                                <div class="col-sm-10">
                                                    <input id="mfile" name="mfile" type="file" class="file"/>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-4 col-sm-offset-2">
                                            <button class="btn btn-primary" type="submit">保存内容</button>
                                            <button data-toggle="modal" type="button" class="btn btn-white"
                                                    href="#modal-form">取消
                                            </button>
                                        </div>
                                    </div>
                                    <input id="hidpic" name="pic" type="hidden" value="" required="required"/>
                                    <input id="id" name="id" type="hidden" value=""/>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div th:include="common/footer_js::footer"></div>
<script>

    //图片上传
    function sendFile(file, editor, $editable) {

        var filename = false;
        try {
            filename = file['name'];
        } catch (e) {
            filename = false;
        }
        if (!filename) {
            $(".note-alarm").remove();
        }
        //以上防止在图片在编辑器内拖拽引发第二次上传导致的提示错误
        data = new FormData();
        data.append("mfile", file);
        data.append("key", filename); //唯一性参数

        $.ajax({
            data: data,
            type: "POST",
            url: "/upload/file?type=sn_Banner",
            cache: false,
            contentType: false,
            processData: false,
            success: function (e) {
                console.log(e)
                if (e && e.code != 0) {
                    swal({title: "上传失败", text: "", type: "error"})
                    return;
                } else {
                    swal({title: "上传成功", text: "", type: "success"})
                }
                editor.insertImage($editable, e.data);
                setTimeout(function () {
                    $(".note-alarm").remove();
                }, 5000);
            },
            error: function () {
                swal({title: "上传失败", text: "", type: "error"})
                return;
            }
        });
    }

    $(document).ready(function () {
        $(".summernote").summernote({
            lang: "zh-CN",
            width: 535,
            height: 260,
            dialogsInBody: true,
            onImageUpload: function (files, editor, $editable) {
                sendFile(files[0], editor, $editable);
            }
        })
    });
</script>
<script src="/js/admin/banner.js"></script>
</body>
</html>
